<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>系统后台 - {$Think.config.INTENDANT_NAME} - by HemaCMS</title>
    <link href="__INTENDANT__/css/admin_style.css" rel="stylesheet" />
    <script src="__COMMON__/jquery.js"></script>
    <script src="__COMMON__/jquery.cookie.js"></script>
    <script src="__COMMON__/layer/layer.js"></script>
    <script src="__INTENDANT__/js/iteny.intendant.js"></script> <!-- 公共easyui JS -->
    <link href="__INTENDANT__/css/iteny.css" rel="stylesheet" />
    <style type="text/css">
    tr{border-left: 1px solid #e5e3e3;}
    td{border-right: 1px solid #e5e3e3;}
    </style>
</head>
<body>
<div class="wrap J_check_wrap">
   	<div class="nav">
  	    <ul class="cc">
  	        <li class="current"><a href="{:U('Site/fileBackup')}/type/export">文件备份</a></li>
  	    </ul>
  	</div>
    <form id="export-form" action="{:U('Site/export')}" method="post">
      <div class="table_list">
        <table width="100%">
          <colgroup>
          <col width="40">
          <col width="40">
          <col width="270">
          <col width="170">
          <!-- <col width="100">
          <col width="50"> -->
          <col width="80">
          <col width="160">
          </colgroup>
          <thead>
            <tr>
              <td width="200" align="center">文件压缩包名称</td>
              <td width="200" align="center">打包时间</td>
              <td width="200" align="center">文件大小</td>
              <td width="200" align="center">操作</td>
            </tr>
          </thead>
          <tbody>
            <volist name="lists" id="vo">
            <tr>
              <td align="center">{$vo.file}</td>
              <td align="center">{$vo.time}</td>
              <td align="center">{$vo.size}</td>
              <td align="center" class="action">
                  <a class="db-import" href="{:U('Site/sendFileZip')}/file/{$vo.file}">发送的指定邮箱</a>&nbsp;|&nbsp;
                  <a class="J_ajax_del" data="{$vo.file}" datatitle="{$vo.file}" href="{:U('Site/delFileBackup')}">删除</a>
              </td>
            </tr>
            </volist>
          </tbody>
        </table>
        <!-- <div class="p10"><div class="pages"> {$Page} </div> </div> -->

      </div>
      <div class="btn_wrap">
        <div class="btn_wrap_pd">
          <button disabledSubmit="" class="btn btn_submit mr10" id="J_ajax_file" type="button">开始备份文件</button>
          <div style="float:right;font-size: 16px;font-weight: bold;
  font-family: Microsoft YaHei,tahoma,arial,'Hiragino Sans GB','\5b8b\4f53',sans-serif;text-align: center;height:32px;line-height:32px;color:#666;">服务器共有{$files}个文件备份，共计{$total}</div>
        </div>
      </div>
    </form>

</div>
<script type="text/javascript">
var filezip = "{:U('Site/zipFileBackup')}";
(function($){
    $('.J_ajax_del').on('click', function (e) {
      e.preventDefault();
      var title = $(this).attr('datatitle');
      var href = $(this).attr('href');
      var data = $(this).attr('data');
      layer.confirm('是否删除备份文件<span style="color:red;">['+title+']</span>', {icon: 3, title:'删除备份文件提示'}, function(index){


          layer.close(index);
          $.ajax({
          type: 'post',
          url: href,
          data : {file : data},
          dataType:"json",
          beforeSend: function(){
            layer.load(1);
          },
          success: function(data){
            layer.close(layer.load(1));
            if(!data.status){
              ITENY.alert('提示信息',data.info,2,'5000');

            } else {
              ITENY.alert('提示信息',data.info,1,'5000');
              setTimeout(function(){
                        ITENY.reloadPage(window);
                    },3000);

            }
          },
          error: function(data){
            layer.close(layer.load(1));
            ITENY.alert('提示信息',data.responseText,2,'5000');

          }
        });
      });
    });
    $(".db-import").click(function(){
        var self = this, status = ".";
        $.get(self.href, success, "json");
        window.onbeforeunload = function(){ return "正在还原数据库，请不要关闭！" }
        return false;

        function success(data){
            if(data.status){
                if(data.gz){
                    data.info += status;
                    if(status.length === 5){
                        status = ".";
                    } else {
                        status += ".";
                    }
                }
                $(self).parent().prev().text(data.info);
                if(data.part){
                    $.get(self.href,
                        {"part" : data.part, "start" : data.start},
                        success,
                        "json"
                    );
                }  else {
                    window.onbeforeunload = function(){ return null; }
                }
            } else {
                ITENY.alert('提示',data.info,2,'3000');
            }
        }
    });
    $('#J_ajax_file').on('click', function (e) {
      e.preventDefault();
      var btn = $(this);
          // form = btn.parents('form.J_ajaxForm');
        if(btn.attr("disabledSubmit")){
          btn.text('请勿重复提交...').prop('disabled', true).addClass('disabled');
          return false;
      }
      btn.attr("disabledSubmit",true);
        $.ajax({
        url: filezip,
        dataType:'json',
        type:'POST',
        beforeSend: function(){
          layer.load(1);
        },
        success: function(data){
          layer.close(layer.load(1));
          if(!data.status){
            ITENY.alert('提示信息',data.info,2,'3000');

          } else {
            ITENY.alert('提示信息',data.info,1,'3000');
            setTimeout(function(){
                      ITENY.reloadPage(window);
                  },3000);

          }
        },
        error: function(data){
          layer.close(layer.load(1));
          ITENY.alert('提示信息',data.responseText,1,'3000');

        }
      });
    });
})(jQuery);

</script>
</body>
</html>